All of our small Java programs look something like this:
class Hello { }
Everything that a program does is described between the first brace and the final, matching brace of a class. To start with, we will have only one class per source code file, but in later chapters there may be several classes per source code file. The example program writes "Hello World!" to the monitor.
class Hello { public static void main ( String[] args ) { System.out.println("Hello World!"); } }
This looks like a lot of work for such a little task! But, usually, programs are much longer and the details you see here help to keep them organized. The line ...
public static void main ( String[] args )
... shows where the program starts running.
The word main
means that this is the
main method --- where the Java virtual machine starts running
the program.
The main method of this program consists of a single statement:
System.out.println("Hello World!");
This statement writes the characters inside the quotation marks to the monitor of the computer system.